package cqrtplm.dto.thirdPartyAPI;

import cn.hutool.core.collection.IterUtil;
import cqrtplm.entity.DspfMbomDetailDO;
import cqrtplm.entity.RtCfgBomDO;
import cqrtplm.entity.RtCfgStatusInfoDO;
import lombok.Data;

import java.util.List;
import java.util.Map;

/**
 * @description: sap物料主数据导入接口参数实体类
 * @author: zhengxiong.jiang
 * @createDate: 2025-09-23
 * @version: 1.0
 */
@Data
public class RestAdapterWlDTO {

    //请求参数
    private InTab IN_TAB;

    //返回参数
    private OutTab OUT_TAB;

    @Data
    public static class InTab {

        private List<InData> item;

    }

    @Data
    public static class InData {
        //物料编码*
        private String MATNR;
        //物料名称
        private String MAKTX;
        //物料类型 (Z001 成品 Z002 零部件 Z003 标准件 Z004 客供料 Z005 辅料 Z006 广宣品 Z099 虚拟物料 客供料 Z005 辅料 Z006 广宣品 Z099 虚拟物料)
        private String MTART;
        //物料类型描述* (成品或空)
        private String MTBEZ;
        //基本计量单位*
        private String MEINS;
        //旧物料号
        private String BISMT;
        //毛重
        private String BRGEW;
        //净重
        private String NTGEW;
        //大小量纲(体积)
        private String GROES;
        //重量单位
        private String GEWEI;
        //体积单位
        private String VOLEH;
        //是否有图纸* (N无图 Y有图 NA无需检查)
        private String ZSJTZ;
        //机型*
        private String ZJX;
        //开发令
        private String ZKFL;
        //成品类别 (1单机动力 2机组动力 3机组)
        private String ZCPLB;
        //物料长文本
        private String ZMAKTX;
        //机械环保代码
        private String ZJXHB;
        //是否半BOM (Y是 其他否)
        private String ZSFBB;
        //半BOM说明
        private String ZBBSM;
        //验证成品码
        private String ZYZCPM;
        //工厂
        private String WERKS;
        //图号 (标件取前10位,成品码为空)
        private String ZTH;
        //采购类型购 (E自制，F采购 机组和动力工厂相同时自制 不同时采购)
        private String BESKZ;

        public InData() {
        }

        public InData(RtCfgStatusInfoDO infoDO, DspfMbomDetailDO detailDO, Map<String, List<String>> ibaAttributeMap) {
            this.MATNR = detailDO.getMaterialcode();
            this.MAKTX = detailDO.getMaterialname();
            this.MTBEZ = detailDO.getDescription();
            List<String> mentList = ibaAttributeMap.get("DefaultUnitMeasurement");
            if(IterUtil.isNotEmpty(mentList)){
                this.MEINS = mentList.get(0);
            }
            List<String> outList = ibaAttributeMap.get("OutputRequirements");
            if(IterUtil.isNotEmpty(outList)){
                String value = outList.get(0);
                if("无".equals(value)){
                    this.ZSJTZ = "NA";
                }
                this.ZSJTZ = "Y";
            }else {
                this.ZSJTZ = "N";
            }
            this.ZJX = infoDO.getProducttype();
            this.ZKFL = infoDO.getDevcode();
            this.WERKS = infoDO.getScgc();
        }

    }

    @Data
    public static class OutTab {

        private List<OutData> item;

    }

    @Data
    public static class OutData {

        //物料编码
        private String MATNR;
        //工厂
        private String WERKS;
        //状态 (S成功;E失败)
        private String MSGTY;
        //执行结果
        private String MSGTXT;

    }

}
